// pages/mima/mima.js
const httpRequest = require('../../utils/http_utils.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pass:'',//新密码
    word:'',//重新输入密码
    info:'',//提示信息
    success:'', //成功提示信息
    error:'', //失败提示信息
    RowGuid:'',
  },

  withdraw: function(){  //返回上一页
    wx.redirectTo({
      url: '../index/index?currentTab=2'
    })
  },

  modifyPass: function (e){ //获取input输入框value值
    this.setData({
      pass : e.detail.value
    })
  },

  modifyWord: function (e){  //获取input输入框value值
    this.setData({
      word : e.detail.value
    })
  },

  confirm: function () {  //非空验证和重复验证以及修改密码
    var that=this;
    if (that.data.pass == null || that.data.pass == undefined || that.data.pass == ""){
      that.setData({
        info : '请输入新密码'
      })
    } else if (that.data.word == null || that.data.word == undefined || that.data.word == ""){
      that.setData({
        info: '请重新确认密码'
      })
    } else if (that.data.pass != that.data.word){
      that.setData({
        info: '两次密码不一致，请重新输入'
      })
    }else{
      let param = {
        RowGuid: that.data.RowGuid,
        password: that.data.pass
      }
      console.log(that.data.pass+'//////////////////////////////////////')
      httpRequest.PostValidateRequest(httpRequest.apiInfo.ProjectUpdatePwdApi,{formdatas : param},
      function(data){
        if(data == 0){
          that.setData({
            success : '修改密码成功，请重新登录！'
          })
          wx.clearStorageSync();
          console.log(wx.getStorageSync("UserInfo"))
          wx.reLaunch({
            url: '../login/login',
          })
        }else{
          that.setData({
            error : '修改密码失败！'
          })
        }
      },
      function(err){

      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.RowGuid = wx.getStorageSync("UserInfo").AppLogin.RowGuid  //获取缓存RowGuid
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})